<template>
    <div>
        <el-form :model="form" label-width="120px" class="demo-ruleForm">
        <div class="container">
            <h4 style="margin-bottom: 20px">{{form.breedName}}</h4>
            <el-button type="primary" @click="handleEdit" v-if="form.status == 0 && qx == 1">分包</el-button>
            <el-button type="primary" @click="handleOk1" v-if="form.status == 1 && sh ==1">通过</el-button>
			<el-button @click="handleNo1" v-if="form.status == 1 && sh ==1">拒绝</el-button>
			<el-button v-if="form.status == 2">审核通过</el-button>
			<el-button v-if="form.status == 1 && sh != 1">待审核</el-button>
			<el-button v-if="form.status == 0 && qx != 1">未分包</el-button>
			<el-row style="margin-top:20px">
				 <el-form-item label="生产批号：">
                        {{form.batch}}
                    </el-form-item>
			</el-row>
            <el-row >
                <el-col :span="12">
                   <el-form-item v-if='switchHeadTab=="生产系统"' label="产品大类：">
                       {{form.inventoryType}}
                   </el-form-item>
                    <el-form-item label="发药机编码：">
                        {{form.dispenserCode}}
                    </el-form-item>
                 <!--   <el-form-item label="分包时间：" v-if="form.status != 0 && form.status != 3 ">
                        {{form.printTime}}
                    </el-form-item> -->
					<el-form-item label="生产日期：">
					    {{form.time}}
					</el-form-item>
                    <el-form-item label="产地：">
                        {{form.address}}
                    </el-form-item>
                    <el-form-item label="生产负责人：">
                        {{form.principalUser}}
                    </el-form-item>
                    <el-form-item label="类型：">
                        {{form.type}}
                    </el-form-item>
                    <el-form-item label="存货代码：">
                        {{form.inventoryCode}}
                    </el-form-item>
                    <el-form-item label="装量：">
                        {{form.materialBreed.pelletWeight}}g
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="存货代码：">
                        {{form.inventoryCode}}
                    </el-form-item>
                    <el-form-item label="投料量：">
                        {{form.scUseNum}}{{form.scUseNumUnits}}
                    </el-form-item>
                    <el-form-item label="分包数量：">
                        <span v-if="form.print == null">未分包</span>
                        <span v-else>{{form.printNum}}包</span>
                    </el-form-item>
					<el-form-item label="保质期：">
					    {{form.deadLine}}月
					</el-form-item>
                </el-col>
            </el-row>

        </div>
        <!-- <div class="container" style="margin-top: 20px">
            <h3 style="margin-bottom: 20px">分包明细</h3>
            <el-table
                :data="tableData"
                border
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="breedName" sortable label="分包时间"></el-table-column>
                <el-table-column prop="printNum" sortable label="分包数量"></el-table-column>
                <el-table-column prop="weight" sortable label="每包装量"></el-table-column>
                <el-table-column prop="totalWeight" sortable label="总计量"></el-table-column>
            </el-table>
        </div> -->
        <el-form-item class="footerFixed">
            <el-button @click="backPage">返回</el-button>
        </el-form-item>
        </el-form>
    </div>
</template>

<script>
import {pack_findById,print_isOk} from "@/request/api";
import { mapState } from 'vuex';
    export default {
        components: {
        },
        data() {
            return {
                form: {
                    materialBreed:''
                },
				qx:1,
				sh:1,
                // tableData: [],
                // total1: 0,
                // currentPage1:1,
                // pagesize1:10,
            };
        },
		 created(){
				var data = JSON.stringify(this.$store.state.fb)
				var a = "分包"
				var b = "审核"
				if(data.indexOf(a) != -1){
					this.qx = 1
				}else{
					this.qx = 2
				}
				if(data.indexOf(b) != -1){
					this.sh = 1
				}else{
					this.sh = 2
				}
			},
        mounted(){
            this.id = this.$route.query.id
            this.init()
        },
        computed:{
            ...mapState(['switchHeadTab'])
        },
        methods: {
			// 通过
			handleOk1(){
			    this.$confirm('此操作将通过该条数据, 是否继续?', '提示', {
			        confirmButtonText: '确定',
			        cancelButtonText: '取消',
			        type: 'warning'
			    }).then(() => {
			        print_isOk({
			            id: this.form.id,
			            status: 2,
			        }).then((res) =>{
			            // var index = this.ruleForm.list.indexOf(item)
			            // if (index !== -1) {
			            //     this.ruleForm.list.splice(index, 1)
			            // }
			            this.$notify({
			                title: '操作成功',
			                message: '通过成功',
			                type: 'success'
			            });
			            this.init()
			        })
			    });
			},
			// 拒绝
			handleNo1(){
			    this.$confirm('此操作将拒绝该条数据, 是否继续?', '提示', {
			        confirmButtonText: '确定',
			        cancelButtonText: '取消',
			        type: 'warning'
			    }).then(() => {
			        print_isOk({
			            id: this.form.id,
			            status: 3
			        }).then((res) =>{

			            this.$notify({
			                title: '操作成功',
			                message: '已拒绝',
			                type: 'success'
			            });
			            this.init()
			        })
			    });
			},
            backPage () {
                this.$router.go(-1);
            },
            init(){
                pack_findById(this.id).then((res) =>{
                    console.log(res);
                    this.form = res.data
                    this.form.loadingQuantity = res.data.materialBreed.loadingQuantity
                    this.form.loadingUnits = res.data.materialBreed.loadingUnits
                    if (this.form.print != null) {
                        this.form.printNum = res.data.print.printNum
                        console.log(res);
                        console.log(this.form.printNum);
                    }
                })
                // print_findByList({
                //     page: this.currentPage1,
                // }).then((res) =>{
                //     this.tableData = res.rows
                //     // this.total1 = res.total
                // })
            },
            //分包
            handleEdit(){
                this.$router.push({
                    path: '/subpackage/operate',
                    query: { id: this.id }
                });
            },
            // handleCurrentChange1(val){
            //     this.currentPage1 = val
            //     this.init()
            // },
        }
    }
</script>
<style scoped lang="less">
.el-pagination{
    text-align: center;
}
</style>
